﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QMSDAL;

namespace QuaManSys.CusSatiSur
{
    public partial class MainPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["CurUser"] != null)
            {
                //根据当前用户的身份显示消息提醒栏
                CurUser user = (CurUser)Session["CurUser"];
                string dept = user.department;
                ShowReminderList(user);
            }
            else
            {
                //跳转到登录页面
                Response.Redirect("~/Login.aspx");
            }
        }

        private void ShowReminderList(CurUser user)
        {
            string emId = user.employeeId;
            //根据emID查询雇员角色
            string dept = user.department;  //雇员部门
            //查询当前用户对内部信息录入和内部收件箱具有的操作权限
            List<string> listOwnedReg = Permission.QueryOpers(emId, "3A");
            List<string> listOwnedRem = Permission.QueryOpers(emId, "3B");
            List<string> listOwnedQue = Permission.QueryOpers(emId, "3C");
            List<string> listDeptReg = Permission.QueryOpers(dept, "3A");
            List<string> listDeptRem = Permission.QueryOpers(dept, "3B");
            List<string> listDeptQue = Permission.QueryOpers(dept, "3C");

            if (listOwnedReg.Count + listOwnedRem.Count + listDeptReg.Count +
                listDeptRem.Count != 0)
            {
                bool completeOrNot = true;
                #region 重新登记

                //需要重新登记的信息
                if (listOwnedReg.Contains("A"))
                {
                    List<string> listInfoReg = Permission.QueryCusInfoStatus("登记");
                    if (listInfoReg.Count != 0)
                    {
                        completeOrNot = false;
                        int inPro = listInfoReg.Count;
                        HyperLink innerHref = new HyperLink();
                        pnlReminder.Controls.Add(innerHref);
                        innerHref.Text = "您共有" + inPro.ToString() +
                            "条顾客满意度信息需要重新登记。";
                        innerHref.NavigateUrl = "CusSatSurReminderBox.aspx";
                        pnlReminder.Controls.Add(new LiteralControl("<br />"));
                    }
                    else
                    {
                        //todo:如果没有需要重新登记的信息
                    }
                }
                #endregion

                #region 待汇总

                //待汇总的信息
                if (listOwnedRem.Contains("C0") || listDeptRem.Contains("C0"))
                {
                    List<string> listInfoDis = Permission.QueryCusInfoStatus("汇总");
                    if (listInfoDis.Count != 0)
                    {
                        completeOrNot = false;

                        int inPro = listInfoDis.Count;
                        HyperLink innerHref = new HyperLink();
                        pnlReminder.Controls.Add(innerHref);
                        innerHref.Text = "您共有" + inPro.ToString() +
                            "条顾客满意度信息信息需要汇总。";
                        innerHref.NavigateUrl = "CusSatSurReminderBox.aspx";
                        pnlReminder.Controls.Add(new LiteralControl("<br />"));

                    }
                }
                #endregion

                //待审核的消息

                #region 待审核
                if (listOwnedRem.Contains("C1") || listDeptRem.Contains("C1"))
                {
                    List<string> listInfoPro = Permission.QueryCusInfoStatus("审核");
                    if (listInfoPro.Count != 0)
                    {
                        completeOrNot = false;
                        int inPro = listInfoPro.Count;
                        HyperLink innerHref = new HyperLink();
                        pnlReminder.Controls.Add(innerHref);
                        innerHref.Text = "您共有" + inPro.ToString() +
                            "条顾客满意度信息信息需要审核。";
                        innerHref.NavigateUrl = "CusSatSurReminderBox.aspx";
                        pnlReminder.Controls.Add(new LiteralControl("<br />"));
                    }
                }
                #endregion

                #region 待收集的消息
                if (listOwnedRem.Contains("C2") || listDeptRem.Contains("C2"))
                {
                    List<string> listInfoPro = Permission.QueryCusInfoStatus("收集");
                    if (listInfoPro.Count != 0)
                    {
                        completeOrNot = false;
                        int inPro = listInfoPro.Count;
                        HyperLink innerHref = new HyperLink();
                        pnlReminder.Controls.Add(innerHref);
                        innerHref.Text = "您共有" + inPro.ToString() +
                            "条顾客满意度信息信息需要收集。";
                        innerHref.NavigateUrl = "CusSatSurReminderBox.aspx";
                        pnlReminder.Controls.Add(new LiteralControl("<br />"));
                    }
                }
                #endregion

                #region 待闭环的消息
                if (listOwnedRem.Contains("D0") || listDeptRem.Contains("D0"))
                {
                    List<string> listInfoPro = Permission.QueryCusInfoStatus("收集");
                    if (listInfoPro.Count != 0)
                    {
                        completeOrNot = false;
                        int inPro = listInfoPro.Count;
                        HyperLink innerHref = new HyperLink();
                        pnlReminder.Controls.Add(innerHref);
                        innerHref.Text = "您共有" + inPro.ToString() +
                            "条顾客满意度信息信息需要闭环。";
                        innerHref.NavigateUrl = "CusSatSurReminderBox.aspx";
                        pnlReminder.Controls.Add(new LiteralControl("<br />"));
                    }
                }
                #endregion

                if (completeOrNot)
                {
                    Label myLabelx = new Label();
                    myLabelx.Text = "当前您需要处理的顾客满意度信息已经处理完毕！";
                    pnlReminder.Controls.Add(myLabelx);
                    pnlReminder.Controls.Add(new LiteralControl("<br />"));
                }
            }
            else
            {
                if (listOwnedQue.Count != 0)
                {
                    Label myLabel = new Label();
                    myLabel.Text = "您是" + dept + "一般用户。可以查询本部门的质量信息。";
                    pnlReminder.Controls.Add(myLabel);
                    pnlReminder.Controls.Add(new LiteralControl("<br />"));
                    TurnToQueryList();
                }
                else
                {
                    Label myLabel = new Label();
                    myLabel.Text = "您当前权限不足，无法操作。请与管理员联系";
                    pnlReminder.Controls.Add(myLabel);
                    pnlReminder.Controls.Add(new LiteralControl("<br />"));
                }
            }

        }
        #region TurnToQueryList();
        private void TurnToQueryList()
        {
            HyperLink innerHref = new HyperLink();
            pnlReminder.Controls.Add(innerHref);
            innerHref.Text = "质量信息查询";
            innerHref.NavigateUrl = "~/CusSatiSur/CusSatiSurQuery.aspx";
            pnlReminder.Controls.Add(new LiteralControl("<br />"));
        }
        #endregion

        /// <summary>
        /// 根据数据库里的记录，自动在panel生成仅显示信息编号的列表
        /// </summary>
        /// <param name="panel"></param>
        /// <param name="i"></param>
        /// <param name="infoId"></param>
        private void FillPanelWithControl(Panel panel, int i, string infoId, string needTo, string url)
        {
            Label myLabel = new Label();
            panel.Controls.Add(myLabel);
            myLabel.Text = i.ToString() + " . 质量信息编号为：" +
                infoId + "需要" + needTo + "。";

            HyperLink innerHref = new HyperLink();
            panel.Controls.Add(innerHref);
            innerHref.Text = "立即处理。";
            innerHref.NavigateUrl = url + "?id=" +
                infoId;
            panel.Controls.Add(new LiteralControl("<br />"));
        }

        //private void show(string dept)
        //{
        //    #region 市场部提醒
        //    if ("市场部" == dept)
        //    {
        //        using (QuaManSysEntities context = new QuaManSysEntities())
        //        {
        //            try
        //            {
        //                pnlCollection.GroupingText = "待汇总客户信息信息";

        //                var info =
        //                    from c in context.CusSatSur
        //                    where c.processStatus.Equals("汇总")
        //                    select new { infomationId = c.infomationId };

        //                if (info.Count() == 0)
        //                {
        //                    Label myLabel = new Label();
        //                    myLabel.Text = "当前没有需要分发的信息！";
        //                    pnlCollection.Controls.Add(myLabel);
        //                }
        //                else
        //                {
        //                    int i = 1;
        //                    string disUrl = "InfomationCollection.aspx";
        //                    foreach (var item in info)
        //                    {
        //                        FillPanelWithControl(pnlCollection, i++, item.infomationId, "汇总", disUrl);
        //                    }
        //                }

        //            }
        //            catch
        //            {
        //                //todo:
        //            }
        //        }
        //    }
        //    #endregion
        //    #region 公司领导
        //    if ("质保部" == dept)   //TODO：将公司领导改成具体的employID
        //    {
        //        using (QuaManSysEntities context = new QuaManSysEntities())
        //        {
        //            try
        //            {
        //                pnlAuditing.GroupingText = "待审核的客户满意度信息";

        //                var info =
        //                    from c in context.CusSatSur
        //                    where c.processStatus.Equals("审核")
        //                    select new { infomationId = c.infomationId };

        //                if (info.Count() == 0)
        //                {
        //                    Label myLabel = new Label();
        //                    myLabel.Text = "当前没有需要审核的信息！";
        //                    pnlAuditing.Controls.Add(myLabel);
        //                }
        //                else
        //                {
        //                    int i = 1;
        //                    string disUrl = "CusSatiSurAuditing.aspx";
        //                    foreach (var item in info)
        //                    {
        //                        FillPanelWithControl(pnlAuditing, i++, item.infomationId, "审核", disUrl);
        //                    }
        //                }

        //            }
        //            catch
        //            {
        //                //todo:
        //            }
        //        }
        //    }
        //    #endregion
        //    #region 质保部
        //    if ("质保部" == dept)   
        //    {
        //        using (QuaManSysEntities context = new QuaManSysEntities())
        //        {
        //            try
        //            {
        //                pnlClose.GroupingText = "待闭环的客户满意度信息";

        //                var info =
        //                    from c in context.CusSatSur
        //                    where c.processStatus.Equals("收集")
        //                    select new { infomationId = c.infomationId };

        //                if (info.Count() == 0)
        //                {
        //                    Label myLabel = new Label();
        //                    myLabel.Text = "当前没有需要闭环的信息！";
        //                    pnlClose.Controls.Add(myLabel);
        //                }
        //                else
        //                {
        //                    int i = 1;
        //                    string disUrl = "CusSatiSurCloseCirle.aspx";
        //                    foreach (var item in info)
        //                    {
        //                        FillPanelWithControl(pnlClose, i++, item.infomationId, "闭环", disUrl);
        //                    }
        //                }

        //            }
        //            catch
        //            {
        //                //todo:
        //            }
        //        }
        //    }
        //    #endregion
        //    using (QuaManSysEntities context = new QuaManSysEntities())
        //    {
        //        try
        //        {
        //            pnlRegist.GroupingText = "待重新登记的客户信息";

        //            var info =
        //                from c in context.CusSatSur
        //                where c.processStatus.Equals("登记")
        //                select new { infomationId = c.infomationId };

        //            if (info.Count() == 0)
        //            {
        //                Label myLabel = new Label();
        //                myLabel.Text = "当前没有需要重新登记的信息！";
        //                pnlRegist.Controls.Add(myLabel);
        //            }
        //            else
        //            {
        //                int i = 1;
        //                string disUrl = "InfomationCollection.aspx";
        //                foreach (var item in info)
        //                {
        //                    FillPanelWithControl(pnlRegist, i++, item.infomationId, "登记", disUrl);
        //                }
        //            }

        //        }
        //        catch
        //        {
        //            //todo:
        //        }
        //    }
        //}
    }
}